package com.summer.study.leetcode.algorithm;

import com.summer.study.leetcode.tree.BinaryTree;
import com.summer.study.leetcode.tree.Tree;
import com.summer.study.leetcode.tree.TreeUtil;

/**
 * @auther: 杨杰
 * @date: 2019/7/31 14:25
 * @description: 对称二叉树
 * https://leetcode-cn.com/problems/symmetric-tree/
 */
public class Demo101 {

    public static void main(String[] args) {
        Tree<Integer> tree = new BinaryTree<>();
        TreeUtil.createSymmetricTreeNodes(tree);
        System.out.println(tree.isSymmetric());
    }

    /*
    递归结束条件：

    都为空指针则返回 true
    只有一个为空则返回 false

    递归过程：

    判断两个指针当前节点值是否相等
    判断 A 的右子树与 B 的左子树是否对称
    判断 A 的左子树与 B 的右子树是否对称

    public boolean isSymmetric(TreeNode root) {
        return isMirror(root, root);
    }

    public boolean isMirror(TreeNode t1, TreeNode t2) {
        if (t1 == null && t2 == null) return true;
        if (t1 == null || t2 == null) return false;
        return (t1.val == t2.val)
            && isMirror(t1.right, t2.left)
            && isMirror(t1.left, t2.right);
    }
    */
}
